package main

import (
	"fmt"
	"net"
)

func main() {
	//监听
	socket, err := net.Listen("tcp", "localhost:8000")
	if err != nil {
		fmt.Println("err =", err)
	}
	defer socket.Close()
	//阻塞等待用户连接
	for {
		conn, err := socket.Accept()
		if err != nil {
			fmt.Println("err =", err)
			return
		}
		defer conn.Close()
		//接收用户请求
		buf := make([]byte, 1024) //1024大小的缓冲区
		n, err1 := conn.Read(buf)
		if err1 != nil {
			fmt.Println("err1 = ", err1)
			return
		}
		fmt.Println("buf = ", string(buf[:n]))
	}
}
